<?php

abstract class IAbstractView implements IView {
	private $values = array();
	/**
	 * Enter description here...
	 *
	 * @var IController
	 */
	private $controller;
	
	private $opts = array();
	
	public function put(array $values = null) {
		if ($values != null) {
			$this->values = array_merge($this->values, $values);
		}
	}
	
	public function values() {
		return $this->values;
	}
	
	public function setController($controller) {
		$this->controller = $controller;
	}
	
	public function controller() {
		return $this->controller;
	}
	
	
	public function tpl($ext = null) {
		$vm = IVM::singleton();
		$tpl = ltrim($vm->nameToC($this->controller->name()) . "/" . $vm->nameToC($this->controller->action()->name()), "/");
		$tpl = str_replace(".", "/", $tpl);
		if ($ext == null) {
			return $tpl;
		}
		else {
			return $tpl . "." . ltrim($ext, ".");
		}
	}
	
	public function init($opts) {
		if (is_array($opts)) {
			$this->opts = $opts;
		}
	}
	
	public function opt($name) {
		$value = isset($this->opts[$name])?$this->opts[$name]:null;
		if ($value != null) {
			$value = str_replace("%{locale}", IApplication::singleton()->locale()->name(), $value);
		}
		return $value;
	}
}

?>